<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.example.beans.UserBean" %>
<%@ page import="com.example.dao.UserDAO" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户信息</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 20px;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            border: 1px solid #ccc;
            padding: 10px;
            text-align: center;
        }
        th {
            background-color: #f2f2f2;
        }
        a {
            color: #3498db;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
        .action-container {
            display: flex;
            justify-content: flex-end;
            margin-top: 15px; /* 调整上下间距 */
        }
    </style>
</head>
<body>
<h1>用户信息</h1>
<table border="1">
    <tr>
        <th>序号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>邮箱</th>
        <th>操作</th>
    </tr>
    <%
        java.util.List<UserBean> users = (java.util.List<UserBean>) request.getAttribute("users");
        if (users == null) {
            UserDAO userDAO = new UserDAO();
            users = userDAO.getAllUsers();
        }
        int index = 1;
        for (UserBean user : users) {
    %>
    <tr>
        <td><%= index++ %></td>
        <td><%= user.getName() %></td>
        <td><%= user.getPassword() %></td>
        <td><%= user.getEmail() %></td>
        <td>
            <a href="change.jsp?userid=<%= user.getUserid() %>">修改</a>
            <a href="deleteUser?userid=<%= user.getUserid() %>">删除</a>
        </td>
    </tr>
    <% } %>
</table>
<!-- 将添加用户和查询功能移到表格下方 -->
<div class="action-container">
    <a href="add.jsp">添加用户</a>
    <form action="queryUser" method="get">
        <input type="text" name="queryName" placeholder="按用户名查询" style="margin-right: 5px;">
        <input type="submit" value="查询">
    </form>
</div>
<div class="student-info">
    <p>班级：软件2414</p>
    <p>学号：241305406</p>
    <p>姓名：王佳男</p>
</div>
</body>
</html>

